<template lang="pug">
.content
  .card
    .card-header(data-background-color='blue')
      h4.title {{user.name}}
      p.category {{user.email}}
    .card-content
      p(v-if="user.mac") 手机号: {{user.phone}}
      p(v-if="user.mac") MAC: {{user.mac}}
      p(v-if="user.company") 公司: {{user.company}}
      p(v-if="user.misc") 备注: {{user.misc}}
      md-button.btn.btn-primary.pull-right(:href="editUrl") 编辑
      md-button.btn.btn-danger.pull-right(@click='deleteUser') 删除
      .clearfix
</template>
<script>
import axios from 'axios'
export default {
  data() {
    return {
      user: {
        company: '',
        name: '加载中...',
        email: '',
        mac: '',
        misc: ''
      }
    }
  },
  computed: {
    editUrl () {
      return '#/users/edit/' + this.user._id
    }
  },
  methods: {
    deleteUser() {
      axios.delete(process.env.API_URL + '/users/id/' + this.$route.params.id)
      .then((response) => this.$router.push({path: '/users'}))
      .catch((error) => console.log(error))
    }
  },
  created() {
    axios.get(process.env.API_URL + '/users/id/' + this.$route.params.id)
    .then(res => { this.user = res.data })
    .catch((error) => console.log(error))
  }
}
</script>

